package com.bwie.pojo;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * description:
 *
 * @Author zhaohaoyang
 * @Create 2025/6/6 16:33
 * @Version 1.0
 */
@Data
public class BasePojo implements Serializable {
    /**
     * 创建人
     */
    private String createdBy;

    /**
     * 创建时间
     */
    private Date createdTime;

    /**
     * 更新人
     */
    private String updatedBy;

    /**
     * 更新时间
     */
    private Date updatedTime;

    public void readyCreate(String token){
        if(token==null){
            this.createdBy="未知";
        }else {
            Claims body = Jwts.parser().setSigningKey("123456").parseClaimsJws(token).getBody();
            Integer userId = body.get("userId", Integer.class);
            this.createdBy=""+userId;
        }

        this.createdTime=new Date();
    }
    public void readyUpdate(String token){
        if(token==null){
            this.updatedBy="未知";
        }else {
            Claims body = Jwts.parser().setSigningKey("123456").parseClaimsJws(token).getBody();
            Integer userId = body.get("userId", Integer.class);
            this.updatedBy=""+userId;
        }
        this.updatedTime=new Date();
    }
}
